/**
 * Created by dev on 99/9/22.
 */
'use strict';
import React, {
    AppRegistry,
    Component,

} from 'react-native';
import {NativeModules} from 'react-native';
import  Util from './util';
const AlipayReact = NativeModules.AlipayModule;
var isIos = Util.isIos();
module.exports = {
    async alipayWithTradeNO( tradeNO, productDescription, amount,returnName,alipaySign,callBack) {
        try {
            if (tradeNO == null || tradeNO == '' || amount == null || amount == '') {
                return false;
            }

            let partner = "2088801728847645";//2088801728847645 趋势支付宝KEY
            let seller = "zj.wang@ecmob.cn";   //趋势支付宝账号
            let privateKey = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAMnPAZOxYM08KbK+knKh2HCggh67R7ob3zR8k1Lq4oWwDKmfkearvnF5wdgogZ/AIXBkYcMi6ArnvVN9etypzRjo7VkZCmIToES1jKVINUmamgNwN56MYA62Hn6usfGF6HL7ZBHvJKqyH+JgBbjNbzK+ZMQe4iQsYJ7SIW1HIktPAgMBAAECgYB9ceIHDsGfkgBRjci23QgPqpZ3x+6kL2Ml2zIw3rUEaRTV88zb2HI/U3I9jaBVzzZ6CMwEYpRfAwJa/ar7s8k60Y3KF+WEDuOk6UShwvfadToJ4JKiC+suusr8gJDU3DcszaeLdbYt9+fb3+xKQhBvGw8FNYTsSn6hVZLy9RkRMQJBAPLM0rpV0WdGz3zrH2yiN6ci9Fcj/FuFwoJpyUU/iCPqyquc6n1dQt0NeL9xDQj4r8RLpnfSbhAbQhAGpPOW6jsCQQDUx67dy+32vfQtuYWCIS5y4KY9AXf/BmUmXD7/dtOgh5LXDxl8ZriYMWtmlyVPvQyTbajt2Bx4BmWq8JaH+n39AkAvfdbeMbkS/WvKYGc2JYjDPXgTr2tGL6S7Q5vl2qZzeBKKfNf1C4/vkxoCQEevcI1Y1P9LwrJanipO3i3Xo7ZPAkEA0Di8SbYXn38RpXFIUiiwcKCgbVCzobAbaeeZips4y34AV04ibZeECwNJi7JbQ+XHmboVNvNmIJp6AUbAuD6L7QJBAJInezvfLJfeiQKJibi9lw5udhKMJPFXKUob8RkUTm2Sw9LCy2dz3IOyVMJMcdVJCZ+OveL/YEGMTZY/HX7h37Q=";
            let notifyURL="http://jiayiapp.xyd.qushiyun.com/index.php?app=paynotify&act=notify_url";
            if (isIos) {

                //IOS 支付
                let apliOrtherinfo = {
                    partner: partner,// //2088801728847645  用户名
                    seller: seller,         //zj.wang@ecmob.cn  用户账号
                    privateKey: privateKey,//阿里巴巴支付 key
                    notifyURL:notifyURL //回调URL
                };
                AlipayReact.pay(tradeNO, 'tpsiteAppIOS' + '-' + tradeNO, productDescription, amount.toString(), apliOrtherinfo,alipaySign,callBack);
                LOG('ios支付===' + tradeNO);
            } else {
                LOG('总额======='+amount)
                // android 支付
                let orderNo = tradeNO.toString(); //订单
                let subject = "tpsiteAppAndroid-" + tradeNO;//商品名
                let body = productDescription.toString();//"商品描述";
                let price = amount.toString();//商品价格;
                let data = '{\"orderNo\":\"' + orderNo
                    + '\",\"subject\":\"' + subject
                    + '\",\"body\":\"' + body
                    + '\",\"price\":\"' + price
                    + '\",\"partner\":\"' + partner
                    + '\",\"seller\":\"' + seller
                    + '\",\"privateKey\":\"' + privateKey
                    + '\",\"notifyURL\":\"' + notifyURL +
                    '\"}';
                AlipayReact.initPay(returnName);
                AlipayReact.pay(data,alipaySign).then(function (data) {

                }, function (err) {

                });
            }
        } catch (e) {

        }
    }
};